package contorller;

import common.Exception.Result;
import common.Exception.Results;
import common.Exception.UserNameIsNullException;
import dto.req.*;
import dto.resp.AuthorLoginRespDTO;
import dto.resp.QueryOneArticleByIdRespDTO;
import entity.ArticleDO;
import entity.AuthorDO;
import service.ArticleService;
import service.AuthorService;

import java.util.ArrayList;

public class AuthorController {
    private AuthorService authorService;


    public AuthorController() {
        authorService = new AuthorService();

    }

    //用户注册
    public Results addUser(AuthorRegisterReqDTO user){
        return authorService.addUser(user);
    }

    /**
     * 查询用户
     * @param username
     * @return 存在返回用户对象，不存在返回空值。
     */
    public Results<AuthorDO> queryUser(String username){
        //查询
        return authorService.queryUser(username);
    }

    /**
     * 用户登录
     */
    public Results<AuthorLoginRespDTO> userLogin(AuthorLoginReqDTO user){
        return  authorService.userLogin(user);
    }

    /**
     * 发布博客文章
     */
    public Results addArticle(AuthorPublishArticleReqDTO articleDO){
      return authorService.addArticle(articleDO);
    }

    /**
     * 删除博客文章
     */
    public Results deleteArticle(Integer articleId,Integer authorId){
        return authorService.deleteArticle(articleId,authorId);
    }

    /**
     * 修改文章内容
     */
    public Results updateArticleTitle(UpdateArticleTitleReqDTO request){
       return authorService.updateArticleTitle(request);
    }


    public Results updateArticleContext(UpdateArticleContextReqDTO request){
       return authorService.updateArticleContext(request);
    }


    /**
     * 点赞功能
     */
    public Results clickFavorite(Integer articleId,Integer authorId){
       return authorService.clickFavorite(articleId,authorId);
    }


    public Results<QueryOneArticleByIdRespDTO> queryOneArticleById(Integer articleId){
        return authorService.queryOneArticleById(articleId);
    }

    /**
     * 评论功能
     */
    public Results commentArticle(AuthorCommentReqDTO request){
        return authorService.commentArticle(request);
    }


    public Results<ArrayList<QueryOneArticleByIdRespDTO>> queryAllArticleByAuthorId(Integer autthorId){
        return authorService.queryAllArticleByAuthorId(autthorId);
    }
}
